{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 [0.28631383, 0.6664511]\n",
      "20 [0.080052786, 0.20989485]\n",
      "40 [0.08899499, 0.20545863]\n",
      "60 [0.093928546, 0.20301153]\n",
      "80 [0.096650384, 0.20166145]\n",
      "100 [0.09815202, 0.20091662]\n",
      "120 [0.09898046, 0.2005057]\n",
      "140 [0.09943753, 0.200279]\n",
      "160 [0.099689685, 0.20015392]\n",
      "180 [0.09982881, 0.20008491]\n",
      "200 [0.09990555, 0.20004684]\n"
     ]
    }
   ],
   "source": [
    "#using numpy to create 100 random nodes\n",
    "x_data = np.random.rand(100)\n",
    "y_data = x_data*0.1+0.2 #weight and bias\n",
    "\n",
    "#create a linear fit\n",
    "b = tf.Variable(1.1)\n",
    "k = tf.Variable(0.5)\n",
    "y = k*x_data + b\n",
    "\n",
    "#quadratic cost function\n",
    "loss = tf.reduce_mean(tf.square(y_data-y))\n",
    "#create an optimizer using gradient descent\n",
    "optimizer = tf.train.GradientDescentOptimizer(0.2)\n",
    "#minimize cost function\n",
    "train = optimizer.minimize(loss)\n",
    "\n",
    "init = tf.global_variables_initializer()\n",
    "\n",
    "with tf.Session() as sess:\n",
    "    sess.run(init)\n",
    "    for step in range(201):\n",
    "        sess.run(train)\n",
    "        if step%20==0:\n",
    "            print(step,sess.run([k,b]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
